import { usePageContext } from "./useContext";

export const useForm = () => {
  const { dispatch } = usePageContext();

  const handleCreate = () => {
    dispatch({ type: "SET_FORM", payload: { current: 1, isEdit: false } });
  };

  const handleEdit = record => {
    dispatch({ type: "SET_FORM", payload: { current: record, isEdit: true } });
  };

  const handleClose = () => {
    dispatch({ type: "SET_FORM", payload: { current: null } });
  };
  return {
    handleCreate,
    handleEdit,
    handleClose
  };
};
